//by Tankbuster
//#define __DEBUG__
#define THIS_FILE "t_delivercontainer.sqf"
#include "x_setup.sqf"
private ["_cargobox", "_epos", "_endtime", "_timewarned"];

if !(call FUNC(checkSHC)) exitWith {};

PARAMS_3(_cargobox,_epos,_endtime);

_timewarned = false;

while {!GVAR(sm_resolved)} do {
	sleep 5;
	if (_cargobox distance _epos < 300) then {
		createVehicle ["smokeshellgreen", _epos ,[],0,"NONE"];
	};
	/*if (!_timewarned && (time > (_endtime - 180))) then
		{//send a single time warning
		[QGVAR(kbmsg), [47]] call FUNC(NetCallEventCTS);
		_timewarned = true;
		};
	if (time > _endtime) then
		{//fail, ran out of time
			GVAR(sm_winner) = -880;
			GVAR(sm_resolved) = true;
		};*/
	if (getPos _cargobox select 2 < 1) then { //box is on the ground
		if (_cargobox distance _epos < 30) then {//mission win;
			GVAR(sm_winner) = 2;
			GVAR(sm_resolved) = true;
		} else {//fail. container on ground away from endpos
			GVAR(sm_winner) = -880;
			GVAR(sm_resolved) = true;
		};
	};
	if (GVAR(IS_HC_CLIENT)) then {
		[QGVAR(sm_var), GVAR(sm_winner)] call FUNC(NetCallEventCTS);
	};
};

sleep 5;
deleteVehicle _cargobox;